package com.hr.system.controller;


import com.hr.common.retrun.R;
import com.hr.system.entity.SysMenu;
import com.hr.system.service.SysMenuService;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hr
 * @since 2024-04-26
 */
@RestController
@RequestMapping("/sys-menu")
@CrossOrigin
public class SysMenuController {

    @Autowired
    private SysMenuService sysMenuService;

    @GetMapping("list")
    public R getList(SysMenu sysMenu) {
        return R.ok(sysMenuService.getList(sysMenu));
    }
    @PostMapping("add")
    public R add(@RequestBody SysMenu sysMenu){
        return R.ok(sysMenuService.add(sysMenu));
    }
    @PostMapping("update")
    public R update(@RequestBody SysMenu sysMenu){
        return R.ok(sysMenuService.update(sysMenu));
    }
    @PostMapping("delete")
    public R delete(@RequestBody Map<String,Integer> map){
        if (sysMenuService.delete(map.get("id"))>0)
            return R.ok("ok");
        else return R.error("error");
    }

    @Operation(summary = "菜单树")
    @GetMapping("tree")
    public R tree(){
        return R.ok(sysMenuService.queryTree());
    }
    @Operation(summary = "菜单和权限")
    @GetMapping("menutree")
    public R menutree(){
        return R.ok(sysMenuService.queryMenuPerms());
    }



}
